home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Sound Cards
/
Programming Sound Cards.iso
/
sound_60
/
sblib.doc
< prev
next >
Wrap
Text File
|
1995-01-01
|
7KB
|
171 lines
SBLIB version 1.0
=================
September 11, 1993
Written by Brian Clayton
HERZOGSoft Programming
SBLIB is a small library of routines for playing .VOC Sound Blaster
sound files in C. The routines make use of the freely-distributable
Sound Blaster driver CTVDSK.DRV. The version of the CTVDSK.DRV driver
included is the Sound Blaster Pro version, but it will work fine on normal
Sound Blasters, too. This driver can be legally distributed with any
programs you write using the library.
All of the routines in the library were written in pure assembler for
simplicity and speed. The routines use large memory model.
This library is freeware. Feel free to do whatever you want with it.
The library contains the following functions:
loaddrv - loads driver CTVDSK.DRV from current directory
initdrv - initializes Sound Blaster, sets sound buffers
playvoc - plays an open .VOC file
stopvoc - stops a currently playing .VOC file
unloaddrv - de-initializes and terminates the driver
setbaseio - sets the base i/o address of sound card
setint - sets interrupt number for DMA
NOTE: Neither setbaseio nor setint has to be used. The driver
assumes default values of 220h and 7, respectively, for each.
If either is used, it must be called before initdrv. (See
description of each, further on.)
For a complete sample program demonstrating the use of all the functions,
see VOCPLAY.C.
unsigned loaddrv( unsigned seg, unsigned size, char *fname )
------------------------------------------------------------
This function loads the driver (CTVDSK.DRV) into the memory block
beginning at seg. Use the _dos_alloc C function to allocate the memory
for the driver. The loaddrv function returns 0 if successful, 1 if
unsuccessful.
The first parameter (seg) is the segment address of the memory block to
load the driver into. This should be the segment address returned by
the _dos_alloc function.
The second parameter (size) is the number of bytes to load into the
memory block specified by seg from the driver. This value should always
be slightly larger than the size of the driver file in bytes.
The last parameter (fname) is a string which contains the filename of
the driver file, including extension. Unless you rename the driver
file, this should be CTVDSK.DRV.
Sample usage:
unsigned x, seg;
_dos_allocmem( 8000 >> 4, &seg );
x = loaddrv( seg, 8000, "CTVDSK.DRV" );
unsigned initdrv( unsigned buf, unsigned *status )
--------------------------------------------------
This function initializes the Sound Blaster, using the driver,
which must have been loaded already using loaddrv. This function
returns 0 if succesful, 1 if unsuccessful.
The first parameter (buf) is the number of 2k disk buffers for the
driver to allocate. This value can range from 1 to 32. Lower values
may make the sound choppier, but larger values use more memory. If
you are unclear about what this parameter does, just try a value such
as 10.
The last parameter (status) should be a far pointer to the status word.
The status word is the unsigned variable that will indicate the status
of the sound. The driver will take care of updating this variable.
When sound is playing, it will contain a non-zero value. When sound is
stopped, it should contain zero. For some reason, however, in the
times I tried, the driver did nothing to the variable, so the status
word variable may not change like it is supposed to. If you are not
sure about what this variable does, just pass a far pointer to an unused
unsigned variable.
Sample usage:
unsigned status;
initdrv( 10, &status );
unsigned playvoc( unsigned fhandle )
------------------------------------
This function is used to play a .VOC file once the driver has been
loaded and initialized using the two functions above. In order to
use this function, you must first use the _dos_open function to open
the .VOC file you wish to play. This function returns 0 is successful.
The fhandle parameter should contain the file handle of the open .VOC
file to play. This should be the file handle returned by the _dos_open
function. When you close the file (using the _dos_close function) the
music will stop, if it has not already.
Sample usage:
unsigned handle;
_dos_open( "test.voc", 0, &handle );
playvoc( handle );
void stopvoc( )
---------------
This function stops any currently playing .VOC file.
Sample usage:
stopvoc( );
void unloaddrv( )
-----------------
This function simply terminates the driver, it does not free up the
memory you allocated for it. You must free the allocated memory using
the _dos_freemem function.
Sample usage:
unloaddrv( );
void setbaseio( unsigned address )
----------------------------------
This function sets the base i/o address in the driver that the Sound
Blaster uses. If this function is not called, the driver assumes the
default, 220h (hex).
NOTE: This function, if used at all, must be called before using
initdrv.
The address parameter is the base i/o address for the Sound Blaster.
For the Sound Blaster Pro, this can be either 220h or 240h. The
normal Sound Blaster has six possible i/o addresses: 210h, 220h, 230h,
240h, 250h, and 260h.
Sample usage:
setbaseio( 0x220 );
void setint( unsigned intr )
----------------------------
This function sets the DMA interrupt number of the Sound Blaster. If
this function is not called, the driver uses the default value of 7.
NOTE: This function, if used at all, must be called before using
initdrv.
The intr parameter is the interrupt number for the DMA. The Sound
Blaster Pro has four possible DMA interrupts: 2, 5, 7, and 10. The
normal Sound Blaster has four possible DMA interrupts: 2, 3, 5, and 7.
Sample usage:
setint( 7 );
----------------------------------------------------------------------------
This library was written and tested on a 40Mhz 386DX with a Sound Blaster
Pro 2. This library is freeware.
----------------------------------------------------------------------------
Feel free to send any questions, comments or suggestions to:
Brian Clayton
6 Granada Terrace
Middletown, RI
02842